/*
 * @Description: 联系方式
 * @Author: iamsmiling
 * @Date: 2021-06-06 22:43:04
 * @LastEditTime: 2021-06-15 17:17:58
 */

import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/image/chimera_image.dart';
import 'package:flutter/material.dart';

class AuthorContactCard extends StatefulWidget {
  final bool anonymous;
  const AuthorContactCard({Key? key, this.anonymous = true}) : super(key: key);

  @override
  _AuthorContactCardState createState() => _AuthorContactCardState();
}

class _AuthorContactCardState extends State<AuthorContactCard> {
  bool anonymous = true;

  @override
  void initState() {
    anonymous = widget.anonymous;
    super.initState();
  }

  Widget _buildPlainTextCard(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(bottom: R.dimen.dp12),
            child: Text(
              "合作联系方式",
              style: TextStyle(
                  fontSize: R.dimen.sp16,
                  color: R.color.ff333333,
                  fontWeight: FontWeight.w600),
            ),
          ),
          Container(
            padding: EdgeInsets.only(
                top: R.dimen.dp20,
                bottom: R.dimen.dp24,
                left: R.dimen.dp24,
                right: R.dimen.dp24),
            decoration: BoxDecoration(
                border: Border.all(color: R.color.ff16c692),
                borderRadius: BorderRadius.circular(R.dimen.sp5),
                color: R.color.fff0fcf9),
            child: Column(
              children: [
                Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(right: R.dimen.dp10),
                      child: ChimeraImage(
                          width: R.dimen.dp40,
                          height: R.dimen.dp40,
                          src:
                              "https://i.loli.net/2021/04/13/2VkqWFU5sxwSQcu.png"),
                    ),
                    Expanded(
                        child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Text(
                              "不会游泳的鱼",
                              style: TextStyle(fontSize: R.dimen.sp13),
                            ),
                            Container(
                              margin: EdgeInsets.only(
                                  left: R.dimen.dp10, right: R.dimen.dp10),
                              child: Image.asset(R.image.realNameAuthed),
                            ),
                            Image.asset(R.image.jobTag)
                          ],
                        ),
                        Container(
                          child: Text(
                            "总经理 | 杭州叮咚网络科技有限公司",
                            style: TextStyle(
                                fontSize: R.dimen.sp11,
                                color: R.color.ff999999),
                          ),
                        )
                      ],
                    ))
                  ],
                ),
                DefaultTextStyle(
                  style: TextStyle(
                      fontSize: R.dimen.sp13, color: R.color.ff333333),
                  child: Container(
                    margin: EdgeInsets.only(top: R.dimen.dp16),
                    child: Row(
                      children: [
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                margin: EdgeInsets.only(bottom: R.dimen.dp16),
                                child: Row(
                                  children: [
                                    Container(
                                      child: Image.asset(R.image.partnerTel),
                                      margin:
                                          EdgeInsets.only(right: R.dimen.dp10),
                                    ),
                                    Text("186 2566 6868"),
                                  ],
                                ),
                              ),
                              Container(
                                child: Row(
                                  children: [
                                    Container(
                                      child: Image.asset(R.image.partnerWx),
                                      margin:
                                          EdgeInsets.only(right: R.dimen.dp8),
                                    ),
                                    Text("GT642943"),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                margin: EdgeInsets.only(bottom: R.dimen.dp16),
                                child: Row(
                                  children: [
                                    Container(
                                      child: Image.asset(R.image.partnerEmail),
                                      margin:
                                          EdgeInsets.only(right: R.dimen.dp10),
                                    ),
                                    Text("35629586@qq.com"),
                                  ],
                                ),
                              ),
                              Container(
                                child: Row(
                                  children: [
                                    Container(
                                      child: Image.asset(R.image.partnerQQ),
                                      margin:
                                          EdgeInsets.only(right: R.dimen.dp10),
                                    ),
                                    Text("35629586"),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget _buildAnonymousCard(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(
          horizontal: R.dimen.dp18, vertical: R.dimen.dp20),
      decoration: BoxDecoration(
          color: R.color.fff0fcf9,
          borderRadius: BorderRadius.circular(R.dimen.sp5),
          border: Border.all(color: R.color.ff16c692)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            child: Text.rich(TextSpan(
                text: "您当前为：",
                style:
                    TextStyle(fontSize: R.dimen.sp14, color: R.color.ff555555),
                children: [
                  TextSpan(
                      text: "普通用户", style: TextStyle(color: R.color.ff19c390)),
                  TextSpan(text: "，可用联系卡"),
                  TextSpan(
                      text: "0", style: TextStyle(color: R.color.ff19c390)),
                  TextSpan(text: "张\n"),
                  TextSpan(text: "今日还可免费查看"),
                  TextSpan(
                      text: "1", style: TextStyle(color: R.color.ff19c390)),
                  TextSpan(text: "次联系方式"),
                  WidgetSpan(
                      child: GestureDetector(
                    onTap: () {},
                    child: Container(
                      margin: EdgeInsets.only(left: R.dimen.dp10),
                      child: Text("开通VIP查看无忧",
                          style: TextStyle(
                              fontSize: R.dimen.sp14, color: R.color.ff19c390)),
                    ),
                  ))
                ])),
          ),
          GestureDetector(
            onTap: () {
              setState(() {
                anonymous = false;
              });
            },
            child: Container(
              width: R.dimen.width,
              alignment: Alignment.center,
              margin: EdgeInsets.only(
                  top: R.dimen.dp15, left: R.dimen.dp25, right: R.dimen.dp25),
              padding: EdgeInsets.symmetric(vertical: R.dimen.dp13),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(R.dimen.sp34),
                  gradient: LinearGradient(
                      colors: [R.color.ff1bbd8d, R.color.ff14ca94])),
              child: Text(
                "点击查看联系方式",
                style: TextStyle(
                    fontSize: R.dimen.sp15,
                    color: R.color.ffffffff,
                    fontWeight: FontWeight.w500),
              ),
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return anonymous
        ? _buildAnonymousCard(context)
        : _buildPlainTextCard(context);
  }
}
